package com.pansky.crm.common.mybatisplus;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;

import java.util.List;
import java.util.Map;
import java.util.function.Function;

public interface SuperService<T> extends IService<T> {
    default <T, F> ResultPageDto defaultTransformPageData(IPage<T> dbResult, Function<List<T>, List<F>> transform) {
        ResultPageDto resultPageDto = new ResultPageDto();
        resultPageDto.setCurrent(dbResult.getCurrent());
        resultPageDto.setPageCount(dbResult.getPages());
        resultPageDto.setTotal(dbResult.getTotal());
        resultPageDto.setSize(dbResult.getSize());
        List<F> rows = (List)transform.apply(dbResult.getRecords());
        resultPageDto.setRows(rows);
        return resultPageDto;
    }

    Map<String, T> getMapByIds(List<String> ids);
}